Conversation
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧Core
Other
🤖 This preview updates automatically when you update the PR. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
packages/aws-serverless/src/integration/instrumentation-aws-lambda/instrumentation.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Adds a bounded timeout around OpenTelemetry forceFlush() in the vendored AwsLambdaInstrumentation._endSpan to prevent AWS Lambda invocations from hanging indefinitely when flush never resolves, and introduces regression tests to verify callback behavior in both hanging and normal flush scenarios.
Changes:
- Wrap
_endSpanflusher waiting in aPromise.racewith a 2s timeout. - Add new
AwsLambdaInstrumentation._endSpanunit tests covering hanging flush, normal flush, and error-to-span metadata behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/aws-serverless/src/integration/instrumentation-aws-lambda/instrumentation.ts | Adds a 2s timeout guard around OTel forceFlush waiting in _endSpan. |
| packages/aws-serverless/test/instrumentation.test.ts | New tests validating _endSpan callback timing and error span annotations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/aws-serverless/src/integration/instrumentation-aws-lambda/instrumentation.ts
Outdated
Show resolved
Hide resolved
packages/aws-serverless/src/integration/instrumentation-aws-lambda/instrumentation.ts
Outdated
Show resolved
Hide resolved
7eb6fef to
b289419
Compare
packages/aws-serverless/src/integration/instrumentation-aws-lambda/instrumentation.ts
Outdated
Show resolved
Hide resolved
size-limit report 📦
|
| () => { | ||
| clearTimeout(timeoutId); | ||
| callback(); | ||
| }, | ||
| () => { | ||
| clearTimeout(timeoutId); | ||
| callback(); | ||
| }, | ||
| ); |
There was a problem hiding this comment.
l: I think we could replace that with just a .finally?
There was a problem hiding this comment.
We still need the catch for handling rejections, not sure if that will ever happen here tho. But finally can reduce the duplication at the very least. 👍
…mbda hanging The vendored AwsLambdaInstrumentation._endSpan calls tracerProvider.forceFlush() without any timeout. Because _endSpan blocks the promise chain before wrapHandler's flush(2000), a hung forceFlush() prevents the Lambda from ever returning — causing it to sit idle until the runtime kills it at its configured timeout. Wrap the flush in a Promise.race with a 2s timeout to match wrapHandler's flush timeout, ensuring the callback always fires within a bounded time. Co-Authored-By: Claude <noreply@anthropic.com> Made-with: Cursor
b289419 to
b517c7e
Compare

The vendored
AwsLambdaInstrumentation._endSpancallstracerProvider.forceFlush()without any timeout.Because
_endSpanblocks the promise chain beforewrapHandler'sflush(2000)can run, a hungforceFlush()prevents the Lambda from ever returning, causing it to sit idle until the runtime kills it at its configured timeout.This was reported by a user whose AppSync authorizer Lambda consistently timed out at 15s despite the handler completing in ~178ms.
The fix wraps the flush in a
Promise.racewith a 2s timeout, matchingwrapHandler's existing flush timeout.closes #20063